<?php
/**
 * RuleCondition
 *
 * PHP version 5
 *
 * @category Class
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */

/**
 * Amazon Ads API for Sponsored Display
 *
 * This API enables programmatic access for campaign creation, management, and reporting for Sponsored Display campaigns. For more information on the functionality, see the [Sponsored Display Support Center](https://advertising.amazon.com/help#GTPPHE6RAWC2C4LZ). For API onboarding information, see the [account setup](https://advertising.amazon.com/API/docs/en-us/guides/onboarding/overview) topic.<br/><br/> > This specification is available for download from the **[Advertising API developer portal](https://d3a0d0y2hgofx6.cloudfront.net/openapi/en-us/sponsored-display/3-0/openapi.yaml).**
 *
 * OpenAPI spec version: 3.0
 * 
 * Generated by:https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api.git
 * AmazonAdvertisingApi Codegen version: 3.0.51
 */
/**
 * NOTE: This class is auto generated by the AmazonAdvertisingApi code generator program.
 *https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 * Do not edit the class manually.
 */

namespace AmazonAdvertisingApi\Model;

use \ArrayAccess;
use \AmazonAdvertisingApi\ObjectSerializer;

/**
 * RuleCondition Class Doc Comment
 *
 * @category Class
 * @description A rule condition that defines the advertiser&#x27;s intent for the outcome of the rule. Certain actions are performed by the product to achieve and maintain the rule condition.
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */
class RuleCondition implements ModelInterface, ArrayAccess
{
    const DISCRIMINATOR = null;

    /**
      * The original name of the model.
      *
      * @var string
      */
    protected static $AmazonAdvertisingApiModelName = 'RuleCondition';

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $AmazonAdvertisingApiTypes = [
        'metric_name' => 'string',
        'comparison_operator' => 'string',
        'threshold' => 'double'
    ];

    /**
      * Array of property to format mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $AmazonAdvertisingApiFormats = [
        'metric_name' => null,
        'comparison_operator' => null,
        'threshold' => 'double'
    ];

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @return array
     */
    public static function AmazonAdvertisingApiTypes()
    {
        return self::$AmazonAdvertisingApiTypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization
     *
     * @return array
     */
    public static function AmazonAdvertisingApiFormats()
    {
        return self::$AmazonAdvertisingApiFormats;
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'metric_name' => 'metricName',
        'comparison_operator' => 'comparisonOperator',
        'threshold' => 'threshold'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'metric_name' => 'setMetricName',
        'comparison_operator' => 'setComparisonOperator',
        'threshold' => 'setThreshold'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'metric_name' => 'getMetricName',
        'comparison_operator' => 'getComparisonOperator',
        'threshold' => 'getThreshold'
    ];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name
     *
     * @return array
     */
    public static function attributeMap()
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @return array
     */
    public static function setters()
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @return array
     */
    public static function getters()
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     *
     * @return string
     */
    public function getModelName()
    {
        return self::$AmazonAdvertisingApiModelName;
    }

    const METRIC_NAME_THOUSAND_VIEWABLE_IMPRESSIONS = 'COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS';
    const METRIC_NAME_CLICK = 'COST_PER_CLICK';
    const METRIC_NAME_ORDER = 'COST_PER_ORDER';
    const COMPARISON_OPERATOR_LESS_THAN_OR_EQUAL_TO = 'LESS_THAN_OR_EQUAL_TO';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getMetricNameAllowableValues()
    {
        return [
            self::METRIC_NAME_THOUSAND_VIEWABLE_IMPRESSIONS,
            self::METRIC_NAME_CLICK,
            self::METRIC_NAME_ORDER,
        ];
    }
    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getComparisonOperatorAllowableValues()
    {
        return [
            self::COMPARISON_OPERATOR_LESS_THAN_OR_EQUAL_TO,
        ];
    }

    /**
     * Associative array for storing property values
     *
     * @var mixed[]
     */
    protected $container = [];

    /**
     * Constructor
     *
     * @param mixed[] $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(array $data = null)
    {
        $this->container['metric_name'] = isset($data['metric_name']) ? $data['metric_name'] : null;
        $this->container['comparison_operator'] = isset($data['comparison_operator']) ? $data['comparison_operator'] : null;
        $this->container['threshold'] = isset($data['threshold']) ? $data['threshold'] : null;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalidProperties = [];

        if ($this->container['metric_name'] === null) {
            $invalidProperties[] = "'metric_name' can't be null";
        }
        $allowedValues = $this->getMetricNameAllowableValues();
        if (!is_null($this->container['metric_name']) && !in_array($this->container['metric_name'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value for 'metric_name', must be one of '%s'",
                implode("', '", $allowedValues)
            );
        }

        if ($this->container['comparison_operator'] === null) {
            $invalidProperties[] = "'comparison_operator' can't be null";
        }
        $allowedValues = $this->getComparisonOperatorAllowableValues();
        if (!is_null($this->container['comparison_operator']) && !in_array($this->container['comparison_operator'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value for 'comparison_operator', must be one of '%s'",
                implode("', '", $allowedValues)
            );
        }

        if ($this->container['threshold'] === null) {
            $invalidProperties[] = "'threshold' can't be null";
        }
        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed
     *
     * @return bool True if all properties are valid
     */
    public function valid()
    {
        return count($this->listInvalidProperties()) === 0;
    }


    /**
     * Gets metric_name
     *
     * @return string
     */
    public function getMetricName()
    {
        return $this->container['metric_name'];
    }

    /**
     * Sets metric_name
     *
     * @param string $metric_name The name of the metric. Supported rule metrics and corresponding supported comparisonOperators: |      MetricName      |ComparisonOperator  |Description| |------------------|--------------------|-------------------| |COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS     |              LESS_THAN_OR_EQUAL_TO             |Maximize viewable impressions while cost per 1000 views less than or equal to `threshold`| |COST_PER_CLICK    |              LESS_THAN_OR_EQUAL_TO            |Maximize page visits while cost per click less than or equal to `threshold`| |COST_PER_ORDER    |              LESS_THAN_OR_EQUAL_TO            |Maximize viewable impressions/page visits/conversion while cost per order less than or equal to `threshold`|
     *
     * @return $this
     */
    public function setMetricName($metric_name)
    {
        $allowedValues = $this->getMetricNameAllowableValues();
        if (!in_array($metric_name, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'metric_name', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['metric_name'] = $metric_name;

        return $this;
    }

    /**
     * Gets comparison_operator
     *
     * @return string
     */
    public function getComparisonOperator()
    {
        return $this->container['comparison_operator'];
    }

    /**
     * Sets comparison_operator
     *
     * @param string $comparison_operator The comparison operator.
     *
     * @return $this
     */
    public function setComparisonOperator($comparison_operator)
    {
        $allowedValues = $this->getComparisonOperatorAllowableValues();
        if (!in_array($comparison_operator, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'comparison_operator', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['comparison_operator'] = $comparison_operator;

        return $this;
    }

    /**
     * Gets threshold
     *
     * @return double
     */
    public function getThreshold()
    {
        return $this->container['threshold'];
    }

    /**
     * Sets threshold
     *
     * @param double $threshold The value of the threshold associated with the metric. The threshold values has defined minimums depending on the metric names in the following table: |                  MetricName            | Minimum of `threshold` Value  | |----------------------------------------|-----------------------------------| |COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS  | 1                                 | |COST_PER_CLICK                          | 0.5                               | |COST_PER_ORDER                          | 5                                 |
     *
     * @return $this
     */
    public function setThreshold($threshold)
    {
        $this->container['threshold'] = $threshold;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param integer $offset Offset
     *
     * @return boolean
     */
    #[\ReturnTypeWillChange]
    public function offsetExists($offset)
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param integer $offset Offset
     *
     * @return mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset)
    {
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
    }

    /**
     * Sets value based on offset.
     *
     * @param integer $offset Offset
     * @param mixed   $value  Value to be set
     *
     * @return void
     */
    #[\ReturnTypeWillChange]
    public function offsetSet($offset, $value)
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param integer $offset Offset
     *
     * @return void
     */
    #[\ReturnTypeWillChange]
    public function offsetUnset($offset)
    {
        unset($this->container[$offset]);
    }

    /**
     * Gets the string presentation of the object
     *
     * @return string
     */
    public function __toString()
    {
        if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print
            return json_encode(
                ObjectSerializer::sanitizeForSerialization($this),
                JSON_PRETTY_PRINT
            );
        }

        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }
}
